<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //数学对象的属性：PI
        console.log(Math.PI);
        //数学对象的方法：
        // abs()  绝对值
        console.log(Math.abs(-10));
        //取整 向上取整 ceil() 向下取整 floor()  四舍五入 round()
        console.log(Math.ceil(9.4));// 10
        console.log(Math.floor(9.8));// 9
        console.log(Math.round(9.4));// 9
        //最大值max()，最小值min()
        console.log(Math.max(5,12,6)); //12
        //定义数组
        var arr = [12,45,76,90];
        console.log(Math.max(...arr));//90
        console.log(Math.min(5,12,6));
        //随机数 random()  >= 0  < 1
        console.log(Math.random());

        //生成 >= min  <max 之间的随机数
        function getRandomArbitrary(min, max) {
            return Math.random() * (max - min) + min;
        }
        console.log(getRandomArbitrary(5,20));

        //生成 >= min <max 之间的随机整数
        function getRandomInt(min, max) {
            const minCeiled = Math.ceil(min);
            const maxFloored = Math.floor(max);
            return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); 
            // 不包含最大值，包含最小值
        }
        console.log(getRandomInt(5,20));
        //生成 >= min <= max 之间的随机整数
        function getRandomIntInclusive(min, max) {
            const minCeiled = Math.ceil(min);
            const maxFloored = Math.floor(max);
            return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // 包含最小值和最大值
        }
        console.log(getRandomIntInclusive(5,20));
    </script>
</body>
</html>